

gen logpop=log(pop)

 histogram st_RoPFI_dim1, bin(20) percent scheme(s2mono)
 swilk st_RoPFI_dim1
 histogram st_RoPFI_dim1 if years_as_democracy>0, bin(20) percent scheme (s2mono)
 swilk st_RoPFI_dim1 if years_as_democracy>0

encode continent, gen(continent_q)
gen europe=1 if continent_q==4
replace europe=0 if europe==.
gen asia=1 if continent_q==3
replace asia=0 if asia==.
gen africa=1 if continent_q==1
replace africa=0 if africa==.
gen americas=1 if continent_q==2
replace americas=0 if americas==.
gen oceania=1 if continent_q==5
replace oceania=0 if oceania==.

gen brit=1 if legal_tradition=="English"
replace brit=0 if legal_tradition!="English"

replace control_of_corruption="." if control_of_corruption=="NA"
destring control_of_corruption, gen(corruption)

gen demo=1 if years_as_democracy>0
replace demo=0 if demo==.

gen newdemo=1 if years_as_democracy<31
replace newdemo=0 if newdemo==.

label variable corruption "Corruption control"
label variable POLCONIII_VDEM "Constraints III"
label variable POLCONV_VDEM "Constraints V"
label variable years_as_democracy "Democratic age"
label variable europe "Europe"
label variable asia "Asia"
label variable americas "Americas"
label variable oceania "Oceania"
label variable africa "Africa"
label variable brit "Common law"
label variable demo "Democracy"
label variable newdemo "New Democracy"
label variable st_RoPFI_dim1 "Regulation of Political Finance"
label variable logpop "Population(logged)"
label variable pop "Population"
label variable public_party_funding "Public Party Funding"

gen nonpart=1 if country=="MICRONESIA"
replace nonpart=1 if country=="MARSHALL ISLANDS"
replace nonpart=1 if country=="NAURU"
replace nonpart=1 if country=="PALAU"
replace nonpart=1 if country=="TONGA"
replace nonpart=1 if country=="TUVALU"



* Descriptives
summarize st_RoPFI_dim1 POLCONIII_VDEM POLCONV_VDEM corruption brit demo newdemo europe asia americas oceania africa if year==2020
outreg2 using descriptive if year==2020, replace  sum(log) keep(public_party_funding st_RoPFI_dim1 POLCONIII_VDEM POLCONV_VDEM corruption brit demo newdemo pop europe asia americas oceania africa) label word 

* POLCONV includes subnat and judicial insts
* POLCONIII includes national representative insts
histogram POLCONIII_VDEM if years_as_democracy>0 & year==2020, scheme(s2mono)
histogram POLCONIII_VDEM if year==2020, scheme(s2mono)
histogram POLCONIII_VDEM if years_as_democracy>0 & year==2020 & pop>500000, scheme(s2mono) percent

twoway (scatter st_RoPFI_dim1 POLCONIII_VDEM if year==2020, sort scheme(s2mono))
twoway (scatter st_RoPFI_dim1 POLCONIII_VDEM if years_as_democracy>0 & year==2020, sort scheme(s2mono))


* MAIN PAPER

* Pub funding

* PolconIII
* All 
logit public_party_funding POLCONIII_VDEM corruption demo newdemo brit asia africa americas oceania logpop if nonpart!=1
outreg2 using public_polconiii, addstat(Pseudo R2, e(r2_p)) replace label word 
* Demos
logit public_party_funding POLCONIII_VDEM corruption demo newdemo brit asia africa americas oceania logpop if nonpart!=1 & years_as_democracy>0
outreg2 using public_polconiii, addstat(Pseudo R2, e(r2_p)) append label word
margins, at(POLCONIII_VDEM=(0(0.1)0.9))
marginsplot, scheme(s2mono) ytitle("Probability of public party funding") title("") xtitle("Political Constraints III") note("Predictive margins from Model 2, Table 1 with 95% confidence intervals")
graph save "Graph" "G:\My Drive\Meanma\Badanie\Referaty\Will\marginsplot_logit_demos.gph", replace
predict resid_pf2 if years_as_democracy>0, residuals
summarize resid_pf2, detail
export excel public_party_funding resid_pf2 POLCONIII_VDEM country using "PolConpaper_resid2" if resid_pf2!=., firstrow(variables) keepcellfmt replace
* Non Demos (americas != 0 predicts success perfectly; oceania omitted because of collinearity.)
logit public_party_funding POLCONIII_VDEM corruption brit asia africa logpop if nonpart!=1 & years_as_democracy==0
outreg2 using public_polconiii, addstat(Pseudo R2, e(r2_p)) append label word

* PolconV
* All 
logit public_party_funding POLCONV_VDEM corruption demo newdemo brit asia africa americas oceania logpop if nonpart!=1
outreg2 using public_polconiii, addstat(Pseudo R2, e(r2_p)) append label word
* Demos
logit public_party_funding POLCONV_VDEM corruption demo newdemo brit asia africa americas oceania logpop if nonpart!=1 & years_as_democracy>0
outreg2 using public_polconiii, addstat(Pseudo R2, e(r2_p)) append label word
* Non Demos (americas != 0 predicts success perfectly; oceania omitted because of collinearity.)
logit public_party_funding POLCONV_VDEM corruption brit asia africa logpop if nonpart!=1 & years_as_democracy==0
outreg2 using public_polconiii, addstat(Pseudo R2, e(r2_p)) append label word

* Regulation
*PolconIII
* All
regress st_RoPFI_dim1 POLCONIII_VDEM corruption demo newdemo brit asia africa americas oceania logpop if nonpart!=1
outreg2 using regress, replace label word 
* Demos
regress st_RoPFI_dim1 POLCONIII_VDEM corruption demo newdemo brit asia africa americas oceania logpop if nonpart!=1 & years_as_democracy>0
outreg2 using regress, append label word 
* NonDemos (oceania collinear)
regress st_RoPFI_dim1 POLCONIII_VDEM corruption brit asia africa americas logpop if nonpart!=1 & years_as_democracy==0
outreg2 using regress,  append label word 

*PolconV
* All 
regress st_RoPFI_dim1 POLCONV_VDEM corruption demo newdemo brit asia africa americas oceania logpop if nonpart!=1
outreg2 using regress, append label word 
* Demos
regress st_RoPFI_dim1 POLCONV_VDEM corruption demo newdemo brit asia africa americas oceania logpop if nonpart!=1 & years_as_democracy>0
outreg2 using regress,  append label word 
* NonDemos (oceania collinear)
regress st_RoPFI_dim1 POLCONV_VDEM corruption brit asia africa americas logpop if nonpart!=1 & years_as_democracy==0
outreg2 using regress,  append label word 


* Case selection after regression
regress st_RoPFI_dim1 POLCONIII_VDEM corruption newdemo brit asia africa americas oceania logpop if years_as_democracy>0 & highsd_demo==0
predict resid_reg if years_as_democracy>0, residuals
summarize resid_reg, detail
gen resid_pf_abs=abs(resid_pf)
export excel public_party_funding st_RoPFI_dim1 resid_pf_abs resid_reg POLCONIII_VDEM country using "PolConpaper_resids_pfandreg" if resid_pf2!=. & resid_reg!=. & highsd_demo==0, firstrow(variables) keepcellfmt replace
* sort by polconiii resid_pf resid_reg
* still picks NLD and Botswana
* NLD max polconiii, Botswana min polconiii, neither highsd of polconiii over time, NLD low resid pub, high resid reg (underpredicted), Botswana lowest resid of zero polcons

* APPENDICES

* A1 w/o excl on non-partisan

* PolconIII
* All 
logit public_party_funding POLCONIII_VDEM corruption demo newdemo brit asia africa americas oceania logpop 
outreg2 using public_polconiii_a1, addstat(Pseudo R2, e(r2_p)) replace label word 
* Demos
logit public_party_funding POLCONIII_VDEM corruption demo newdemo brit asia africa americas oceania logpop if years_as_democracy>0
outreg2 using public_polconiii_a1, addstat(Pseudo R2, e(r2_p)) append label word
* Nondemos (americas and oceania omitted cos predict success and failure perfectly )
logit public_party_funding POLCONIII_VDEM corruption brit asia africa logpop if years_as_democracy==0
outreg2 using public_polconiii_a1, addstat(Pseudo R2, e(r2_p)) append label word

* PolconV
* All 
logit public_party_funding POLCONV_VDEM corruption demo newdemo brit asia africa americas oceania logpop 
outreg2 using public_polconiii_a1, addstat(Pseudo R2, e(r2_p)) append label word
* Demos
logit public_party_funding POLCONV_VDEM corruption demo newdemo brit asia africa americas oceania logpop if years_as_democracy>0
outreg2 using public_polconiii_a1, addstat(Pseudo R2, e(r2_p)) append label word
* Non Demos (americas != 0 predicts success perfectly; oceania omitted because of collinearity.)
logit public_party_funding POLCONV_VDEM corruption brit asia africa logpop if years_as_democracy==0
outreg2 using public_polconiii_a1, addstat(Pseudo R2, e(r2_p)) append label word

* Regulation
*PolconIII
* All
regress st_RoPFI_dim1 POLCONIII_VDEM corruption demo newdemo brit asia africa americas oceania logpop 
outreg2 using regress_a1, replace label word 
* Demos
regress st_RoPFI_dim1 POLCONIII_VDEM corruption demo newdemo brit asia africa americas oceania logpop if  years_as_democracy>0
outreg2 using regress_a1, append label word 
* NonDemos 
regress st_RoPFI_dim1 POLCONIII_VDEM corruption brit asia africa americas oceania logpop if years_as_democracy==0
outreg2 using regress_a1,  append label word 

*PolconV
* All 
regress st_RoPFI_dim1 POLCONV_VDEM corruption demo newdemo brit asia africa americas oceania logpop 
outreg2 using regress_a1, append label word 
* Demos
regress st_RoPFI_dim1 POLCONV_VDEM corruption demo newdemo brit asia africa americas oceania logpop if years_as_democracy>0
outreg2 using regress_a1,  append label word 
* NonDemos (oceania collinear)
regress st_RoPFI_dim1 POLCONV_VDEM corruption brit asia africa americas logpop if years_as_democracy==0
outreg2 using regress_a1,  append label word 

* A2 1m pop dummy
gen pop1m=1 if pop>999999
replace pop1m=0 if pop1m==.
replace pop1m=. if pop==.
* PolconIII
* All 
logit public_party_funding POLCONIII_VDEM corruption demo newdemo brit asia africa americas oceania logpop pop1m if nonpart!=1
outreg2 using public_polconiii_a2, addstat(Pseudo R2, e(r2_p)) replace label word 
* Demos
logit public_party_funding POLCONIII_VDEM corruption demo newdemo brit asia africa americas oceania logpop pop1m if years_as_democracy>0 & nonpart!=1
outreg2 using public_polconiii_a2, addstat(Pseudo R2, e(r2_p)) append label word
* Nondemos (americas and oceania omitted cos predict success and failure perfectly )
logit public_party_funding POLCONIII_VDEM corruption brit asia africa logpop pop1m if years_as_democracy==0 & nonpart!=1
outreg2 using public_polconiii_a2, addstat(Pseudo R2, e(r2_p)) append label word

* PolconV
* All 
logit public_party_funding POLCONV_VDEM corruption demo newdemo brit asia africa americas oceania logpop pop1m if nonpart!=1
outreg2 using public_polconiii_a2, addstat(Pseudo R2, e(r2_p)) append label word
* Demos
logit public_party_funding POLCONV_VDEM corruption demo newdemo brit asia africa americas oceania logpop pop1m if years_as_democracy>0 & nonpart!=1
outreg2 using public_polconiii_a2, addstat(Pseudo R2, e(r2_p)) append label word
* Non Demos (pop1m omitted predicts success perfectly)
logit public_party_funding POLCONV_VDEM corruption brit asia africa logpop if years_as_democracy==0 & nonpart!=1
outreg2 using public_polconiii_a2, addstat(Pseudo R2, e(r2_p)) append label word

* Regulation
*PolconIII
* All
regress st_RoPFI_dim1 POLCONIII_VDEM corruption demo newdemo brit asia africa americas oceania logpop pop1m if nonpart!=1
outreg2 using regress_a2, replace label word 
* Demos
regress st_RoPFI_dim1 POLCONIII_VDEM corruption demo newdemo brit asia africa americas oceania logpop pop1m if  years_as_democracy>0 & nonpart!=1
outreg2 using regress_a2, append label word 
* NonDemos 
regress st_RoPFI_dim1 POLCONIII_VDEM corruption brit asia africa americas oceania logpop pop1m if years_as_democracy==0 & nonpart!=1
outreg2 using regress_a2,  append label word 

*PolconV
* All 
regress st_RoPFI_dim1 POLCONV_VDEM corruption demo newdemo brit asia africa americas oceania logpop pop1m if nonpart!=1
outreg2 using regress_a2, append label word 
* Demos
regress st_RoPFI_dim1 POLCONV_VDEM corruption demo newdemo brit asia africa americas oceania logpop pop1m if years_as_democracy>0 & nonpart!=1
outreg2 using regress_a2,  append label word 
* NonDemos (oceania collinear)
regress st_RoPFI_dim1 POLCONV_VDEM corruption brit asia africa americas logpop pop1m if years_as_democracy==0 & nonpart!=1
outreg2 using regress_a2,  append label word 

* A3 less highsd on polconiii
* PolconIII
* All (oceania predicts failure perfectly)
logit public_party_funding POLCONIII_VDEM corruption demo newdemo brit asia africa americas logpop if nonpart!=1 & highsd==0
outreg2 using public_polconiii_a3, addstat(Pseudo R2, e(r2_p)) replace label word 
* Demos (oceania predicts failure perfectly)
logit public_party_funding POLCONIII_VDEM corruption demo newdemo brit asia africa americas logpop if nonpart!=1 & years_as_democracy>0 & highsd==0
outreg2 using public_polconiii_a3, addstat(Pseudo R2, e(r2_p)) append label word
* Nondemos (oceania collinearity, americas predicts success )
logit public_party_funding POLCONIII_VDEM corruption brit asia africa logpop if nonpart!=1 & years_as_democracy==0 & highsd==0
outreg2 using public_polconiii_a3, addstat(Pseudo R2, e(r2_p)) append label word

* Regulation
*PolconIII
* All
regress st_RoPFI_dim1 POLCONIII_VDEM corruption demo newdemo brit asia africa americas oceania logpop if nonpart!=1 & highsd==0
outreg2 using regress_a3, replace label word 
* Demos
regress st_RoPFI_dim1 POLCONIII_VDEM corruption demo newdemo brit asia africa americas oceania logpop if nonpart!=1 & years_as_democracy>0 & highsd==0
outreg2 using regress_a3, append label word 
* NonDemos (oceania collinearity)
regress st_RoPFI_dim1 POLCONIII_VDEM corruption brit asia africa americas logpop if nonpart!=1 & years_as_democracy==0 & highsd==0
outreg2 using regress_a3,  append label word 

